package com.chengxiaoxiao.ai_demo.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 状态码
 *
 * @Description:
 * @Author Cheng Xiaoxiao
 * @Date: 2025/3/10 14:00
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CodeMsg implements Serializable {
    /**
     * 校验不通过异常
     */
    public static final CodeMsg BIND_ERROR = new CodeMsg("A00001", "%s");

    /**
     * 业务相关错误码
     */
    public static final CodeMsg CONVERSATION_NOT_FOUND = new CodeMsg("B00001", "会话信息不存在");

    /**
     * 指令相关错误码
     */
    public static final CodeMsg INSTRUCTION_NOT_FOUND = new CodeMsg("B01001", "指令名称已存在");


    /**
     * 第三方错误码
     */
    public static final CodeMsg REQUEST_ERROR = new CodeMsg("C00001", "网络连接错误：%s");


    /**
     * 成功的code
     */
    private static final String CODE_SUCCESS = "0";
    /**
     * 成功的返回信息
     */
    public static final CodeMsg SUCCESS = new CodeMsg(CODE_SUCCESS, "success");


    /**
     * 失败的code
     */
    private static final String CODE_ERROR = "500";
    /**
     * 失败返回信息
     */
    public static final CodeMsg ERROR = new CodeMsg(CODE_ERROR, "success");
    private String code;
    private String msg;

    /**
     * 添加带参数的错误异常
     *
     * @param obj 填充的参数对象
     * @return 填充过后的数据
     */
    public CodeMsg fillArgs(Object... obj) {
        String message = String.format(msg, obj);
        return new CodeMsg(code, message);
    }
}